/**    
 * @{#} RegisterActivity.java Create on 2014-5-26 下午9:51:05    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin;

import java.util.HashMap;

import org.json.JSONObject;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import cn.o.app.ui.OAlert;
import cn.o.app.ui.OAlert.OAlertListener;
import cn.skinapp.R;

import com.evan.common.handler.RequestHandler;
import com.evan.common.handler.callback.HandlerCallback;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.intercept.RequestTaskIntercept;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;
import com.umeng.analytics.MobclickAgent;

public class ResetPayPasswordActivity extends BasicActivity {

	private EditText edit_password, edit_confirm_password;

	private String sms_code;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reset_pay_password);
		init();
		back.setVisibility(View.GONE);
		setNavTitle("支付密码设置");

		edit_password = (EditText) findViewById(R.id.edit_password);
		edit_confirm_password = (EditText) findViewById(R.id.edit_confirm_password);

		sms_code = getIntent().getStringExtra(Constant.IDENTITY_KEY_SMS);

	}

	public void onClick(View view) {
		int id = view.getId();
		if (id == R.id.btn_submit) {
			String password = edit_password.getText().toString();
			String confirm_password = edit_confirm_password.getText()
					.toString();
			if (CommonUtility.isNull(password)) {
				CommonUtility.tip(activity, "密码不能为空");
				return;
			}
			if (CommonUtility.isNull(confirm_password)) {
				CommonUtility.tip(activity, "确认密码不能为空");
				return;
			}
			if (!CommonUtility.isNull(password)
					&& !CommonUtility.isNull(confirm_password)) {
				if (password.length() >= 8 && password.length() <= 16) {
					if (password.equals(confirm_password)) {
						HashMap<String, Object> params = new HashMap<String, Object>();
						params.put(Constant.PARAM_API, "Account.SetPayPwd");
						params.put("PayPwd", password);
						params.put(Constant.PARAM_TOKEN, GlobalSettings.sToken);
						params.put("ConfirmCode", sms_code);
						params.put("ConfirmCodeType", 2);
						RequestTaskIntercept.requestIntercept(activity,
								Constant.URL.REQUEST, new RequestHandler(
										activity, new HandlerCallback() {

											@Override
											public void callback(Object o) {
												if (!CommonUtility.isNull(o)) {
													JSONObject object = (JSONObject) o;
													if (CommonUtility
															.response200(object)) {
														OAlert alert = new OAlert(
																activity);
														alert.setOK("确认");
														alert.setTitle("支付密码设置成功");
														alert.show();
														alert.setListener(new OAlertListener() {

															@Override
															public boolean onOK(
																	OAlert alert) {
																CommonUtility
																		.finishActivityFromName(RegisterSecondStepActivity.class
																				.getSimpleName());
																finish();
																return false;
															}

															@Override
															public boolean onCancel(
																	OAlert alert) {
																return false;
															}
														});
													} else {
														try {
															CommonUtility
																	.tip(activity,
																			object.getString("ResultMessage"));
														} catch (Exception e) {
															e.printStackTrace();
														}
													}
												}
											}
										}), params);
					} else {
						CommonUtility.tip(activity, "两次密码输入不一致");
					}
				} else {
					CommonUtility.tip(activity, "密码长度为8-18");
				}
			} else {
				CommonUtility.tip(activity, "密码不能为空");
			}
		}
	}
	
/*	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}*/
}
